const app = getApp()
const { fetchBannerBasic ,fetchFastBasic} = require('../../utils/api.js')
import Storage from '../../utils/storage'
const { baseUrl } = require('../../utils/http')
Page({
	data: {
		// 轮播图配置
		indicatorDots: true,        // 是否显示指示点
		autoplay: true,             // 是否自动播放
		interval: 3000,             // 自动切换时间间隔
		duration: 500,              // 滑动动画时长
		circular: true,             // 是否循环播放
		indicatorColor: 'rgba(255, 255, 255, 0.6)',      // 指示点颜色
		indicatorActiveColor: '#ffffff', // 当前指示点颜色
		
		// 轮播图数据
		swiperList: [],
		fastList: []
	},
	onLoad() {
		this.initBanner()
		this.initFast()
	},
	initBanner: async function () {
		const result = await fetchBannerBasic({ mode: 1 })
		if (result.code == 1) {
			const list = result.data
			list.forEach(element => {
				element.image = baseUrl + element.image
			})
			this.setData({
				swiperList: list
			})
		}
	},
	initFast: async function () {
		const result = await fetchFastBasic()
		if (result.code == 1) {
			const list = result.data
			list.forEach(element => {
				element.icon = baseUrl + element.icon
			})
			this.setData({
				fastList: list
			})
		}
	},
	naviToPage: function (event) {
		const url = event.currentTarget.dataset.url
		wx.navigateTo({
			url: url
		})
	},
	// 轮播图点击事件
	onSwiperTap:function(e) {
		const index = e.currentTarget.dataset.index
		const item = this.data.swiperList[index]
		
		if (item.link) {
			wx.navigateTo({
				url: item.link
			})
		}
	},
	
	// 跳转到AI助手页面
	seeRcode: function() {
		wx.navigateTo({
			url: '/pages/ai/index'
		})
	}
})